package io;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;

public class WriteStringDemo3 {
    public static void main(String[] args) throws FileNotFoundException {
        //低级流:文件流，负责向文件中写入字节
        FileOutputStream fos=new FileOutputStream("./fos.txt");
        //高级流:OutputStreamWriter,负责向写出的字符串按照指定字符集转换为字节
        OutputStreamWriter osw=new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        //高级流:PrintWriter,负责按行写出字符串
        PrintWriter pw=new PrintWriter(osw);
        pw.write("和我在成都的街头走一走;");
        pw.write("直到所有的灯都熄灭了也不停留");
        System.out.println("数据写出完毕");
        pw.close();
    }
}
